    <?php

    /////////////////////////////////////////////
    // These are the variables you need to change
    /////////////////////////////////////////////

    // your app api key
    $appapikey = '83cc71d0dbb650cf0d8af70a0bd053cb';
    // your app secret
    $appsecret = 'ab118d139d347dbb714c62f6915ef1b9';
    // your callback url
    $appcallbackurl = 'http://googlewala.com/fb8/';
    // your facebook url of this page
    $inviteurl = 'http://apps.facebook.com/hot_gallery/index.php';

    /////////////////////////////////////////////
    // This is the beginning of the section which includes and set up the php5 rest lib
    /////////////////////////////////////////////

    require_once '../client/facebook.php';

    $facebook = new Facebook($appapikey, $appsecret);
    $user = $facebook->require_login();

    //catch the exception that gets thrown if the cookie has an invalid session_key in it
    try {
    if (!$facebook->api_client->users_isAppAdded()) {
    $facebook->redirect($facebook->get_add_url());
    }
    } catch (Exception $ex) {
    //this will clear cookies for your application and redirect them to a login prompt
    $facebook->set_user(null, null);
    $facebook->redirect($appcallbackurl);
    }

    /////////////////////////////////////////////
    // These are the variables may want to change
    /////////////////////////////////////////////
    // The title of your Invite message
    $title = 'You have been invited to join on hot gallery application';
    // The body of your Invite message
    $text = '<fb:name uid="'.$user.'" firstnameonly="true" /> invited you to join this app. <fb:pronoun uid="'.$user.'" /> wants you to join.<fb:req-choice url="'.$facebook->get_add_url().'" label="Add it" />';
    // The logo associated with your invite message
    $logo = 'http://www.rics.org/NR/rdonlyres/A9184764-B56A-4EE2-8AB2-0A765CDB935C/0/peppers_hot.jpg';
    // Success message for when invites succeeded
    $iworked = '<fb:success><fb:message>Your invitations have been sent</fb:message></fb:success>';
    // Error message for when all invites have been used
    $ierror = '<fb:error><fb:message>You are out of invites, try again tomorrow</fb:message></fb:error>';

    /////////////////////////////////////////////
    // This is the beginning of the section that processes the invites
    /////////////////////////////////////////////
    if ($_POST['ids']) {
    // Invite the friends that were selected.
    $friends = array();
    foreach ($_POST['ids'] as $value) {
    if (count($friends) < 10) {
    $friends[count($friends)] = $value;
    }
    }
    $tail = '&canvas';
    $url = $facebook->api_client->notifications_sendRequest($friends, $title, $text, $logo, true);

    if(!$url){
    // If the maximum number of invites has been reached
    $facebook->redirect($inviteurl."?i=1");
    exit;
    }else{
    $facebook->redirect($url.$tail);
    exit;
    }
    }

    if ($_GET['sent'] == 1) {
    // Display a message letting the user know invitations have been successfully sent.
    echo $iworked;
    }

    if($i=="1"){
    // Error message for when all invites have been used
    echo $ierror;
    }

    /////////////////////////////////////////////
    // This is the beginning of the actual invite form
    /////////////////////////////////////////////
    echo '<div style="margin:20px; height:400px;">
    <h2>Invite some Friends</h2>
    <form action="'.$inviteurl.'" method="post"><fb:multi-friend-input width="350px" border_color="#8496ba" /><input type="submit" value="Invite" /></form>
    </div>';

    ?>